package com.ding.easycontroller.file;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

import java.io.File;
import java.util.Properties;

@Component
public class PluginFilePathHolder {
    private File root;

    public PluginFilePathHolder(@Value("${plugin.path:}") String path) {
        String root;
        if (path.equals("")) {
            Properties properties = System.getProperties();
            root = properties.getProperty("user.home") + File.separator + ".plugin";
            System.out.println("插件路径:" + root);
        } else {
            root = path;
        }
        File file = new File(root);
        if (!file.exists() && !file.mkdirs()) {
            throw new RuntimeException("路径创建失败:" + file.getAbsolutePath());
        }
        this.root = file;
    }

    public File getRoot() {
        return root;
    }
}
